package com.bdqn.service.impl;

import com.bdqn.mapper.Sys_menuMapper;
import com.bdqn.pojo.Sys_menu;
import com.bdqn.service.Sys_menuService;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.awt.*;
import java.util.ArrayList;
import java.util.List;

@Service
public class Sys_menuServiceImpl implements Sys_menuService {
    @Autowired
    Sys_menuMapper mapper;
    @Override
    public List<Sys_menu> getUserMenus(int userid) {
        List<Sys_menu> list=new ArrayList<>();
        //获取当前用户的所有父菜单
        list=mapper.selectParentMenuByUid(userid);
        //根据父菜单编号，查询用户父菜单下所有的子菜单
        for (Sys_menu pmenu:list) {
            //获取父菜单编号
            int pid=pmenu.getMenuid();
            //查询用户父菜单下所有的子菜单
            List<Sys_menu> childeMenuList= mapper.selectChildMenusByUidAndPid(userid,pid);
            //放到父菜单下
            pmenu.setChildMenuList(childeMenuList);
        }
        return list;    }

    @Override
    public List<Sys_menu> getMenusAll() {
        List<Sys_menu> list=new ArrayList<>();
        //获取所有父菜单
        list=mapper.selectParentMenus();
        //根据父菜单编号，查询父菜单下所有的子菜单
        for (Sys_menu pmenu:list) {
            //获取父菜单编号
            int pid=pmenu.getMenuid();
            //查询父菜单下所有的子菜单
            List<Sys_menu> childeMenuList=mapper.selectChildMenusByPid(pid);
            //放到父菜单下
            pmenu.setChildMenuList(childeMenuList);
        }
        return list;
    }
}
